package com.ruoyi.admin.train.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.train.domain.TrainPlan;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.admin.train.service.IadminTrainPlanService;


/**
 * 培训计划Controller
 * 
 * @author wusihao
 * @date 2023-03-18
 */
@Api(tags = "审核培训计划")
@RestController
@CrossOrigin
@RequestMapping("/admintrain/plan")
public class adminTrainPlanController extends BaseController
{
    @Autowired
    private IadminTrainPlanService adminTrainPlanService;

    /**
     * 查询培训计划列表
     */
    @ApiOperation("查询已提交的培训计划表")
    @GetMapping("/list")
    public TableDataInfo list(TrainPlan adminTrainPlan)
    {
        startPage();
        List<TrainPlan> list = adminTrainPlanService.selectadminTrainPlanList(adminTrainPlan);
        return getDataTable(list);
    }

    /**
     * 导出培训计划列表
     */
    @ApiOperation("导出已提交的培训计划表")
    @Log(title = "培训计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainPlan adminTrainPlan)
    {
        List<TrainPlan> list = adminTrainPlanService.selectadminTrainPlanList(adminTrainPlan);
        ExcelUtil<TrainPlan> util = new ExcelUtil<TrainPlan>(TrainPlan.class);
        util.exportExcel(response, list, "培训计划数据");
    }

    /**
     * 获取培训计划详细信息
     */
    @ApiOperation("获取已提交的培训计划表的详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(adminTrainPlanService.selectadminTrainPlanById(id));
    }


    /**
     * 修改培训计划
     */
    @ApiOperation("修改培训计划")
    @Log(title = "培训计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainPlan adminTrainPlan)
    {
        return toAjax(adminTrainPlanService.updateadminTrainPlan(adminTrainPlan));
    }

    /**
     * 审核培训计划
     */
    @ApiOperation("审核培训计划")
    @Log(title = "培训计划", businessType = BusinessType.UPDATE)
    @GetMapping("/audit/{trainId}/{status}")
    public AjaxResult audit(@PathVariable Long trainId, @PathVariable Long status)
    {
        return toAjax(adminTrainPlanService.submitAudit(trainId, status));
    }

}
